﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using SportStore.WebUI.HtmlHelpers;
using System.Web.Mvc;
using SportStore.WebUI.Models;
using SportStore.Domain.Entities;
using SportStore.WebUI.Controllers;

namespace SportStore.UnitTests
{
    [TestFixture]
    public class DisplayingPageLinks
    {
        [Test]
        public void Can_Generate_Links_To_Other_Pages()
        {
            HtmlHelper html = null;

            PageInfo pagingInfo = new PageInfo
            {
                CurrentPage = 2,
                TotalItems = 12,
                ItemsPerPage = 4
            };
            Func<int, string> pageUrl = i => "Page" + i;

            MvcHtmlString result = html.PageLinks(pagingInfo, pageUrl);

            result.ToString().ShouldEqual(@"<a href=""Page1"">1</a>
<a class=""seletected"" href=""Page2"">2</a>
<a href=""Page3"">3</a>
");
        }

        [Test]
        public void Products_List_Include_Correct_PageNumbers()
        {
            var mockProductsRepository = UnitTestHelpers.MockProductsRepository(
                new Product { Name = "P1" },
                new Product { Name = "P2" },
                new Product { Name = "P3" },
                new Product { Name = "P4" },
                new Product { Name = "P5" }
                );
            var controller = new ProductsController(mockProductsRepository) { PageSize = 3 };

            var result = controller.List(null, 2);

            var ViewModel = (ProductsListViewModel)result.ViewData.Model;
            PageInfo pagingInfo = ViewModel.PagingInfo;
            pagingInfo.CurrentPage.ShouldEqual(2);
            pagingInfo.ItemsPerPage.ShouldEqual(3);
            pagingInfo.TotalPages.ShouldEqual(2);
            pagingInfo.ItemsPerPage.ShouldEqual(3);
        }
        
    }
}
